package io.gitee.tianhaoran.chat.sdk.api;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import java.util.Set;

/**
 * 校验
 * <p>
 * 作者：沈自在
 **/
public class ValidProvider {

    /**
     *
     */
    private static Validator validator;

    // init
    static {
        ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
        validator = factory.getValidator();
    }

    /**
     * 校验方法
     */
    public static boolean validate(Object obj, Class<?> group) {
        Set<ConstraintViolation<Object>> validate =
                validator.validate(obj, group);
        return validate.isEmpty();
    }
}
